<%@ page contentType="text/html;charset=UTF-8" %>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Sample title</title>
    <meta name="layout" content="main" />
  </head>
  <body>
      <div id="pageBody">
          <h1>View Product Detail</h1>
          
          <br/>${flash.message}<br/><br/>

          <g:form name="updateWineProductForm" controller="cartManagement" action="addToCart">

              <input type="hidden" name="id" value="${product.id}"/>
              <input type="hidden" name="productType" value="${productType}"/>
              <img src="${product.imageUrl}" alt="" height="150px"/><br/><br/>
              Product Name: ${product.productName}<br/>
              Description: ${product.description}<br/>
              Product Type: ${productType}<br/>

              <br/>
              <h3>Product Options</h3>
        <!--      if possible maybe can make a list of product options returned by service web service-->
              <g:if test="${productType == 'Wine'}">
                  <u>For Wine</u><br/>
                  Wine Type: ${wineTypeName}<br/>
                  Wine Varietal: ${wineVarietalName}<br/>
                  Wine Region: ${wineRegionName}<br/><br/>
              </g:if>
        
              Price: USD ${product.sellingPrice}<br/><br/>
        
              <input type="text" name="quantity" size="3" value="1"/>

              <input type="submit" value="Add to Cart" action="addToCart"/>
            
          </g:form>
          
          <br/>
          <hr/>
          <br/>
          <g:if test="${ratingCount > 0}">
              Overall Rating: ${averageRating}
          </g:if>
          <g:if test="${ratingCount == 0}">
              Overall Rating: N.A.
          </g:if>
          <br/>
          <br/>
          <hr/>
          <br/>
            
          <g:form name="commentProductForm" controller="contentManagement" action="productRatingComment">
            
              <g:if test="${session.customerId}">
                  <input type="hidden" name="customerId" value="${session.customerId}"/>
                  <input type="hidden" name="productId" value="${product.id}"/>
                  Rate it: <input type="text" name="productRating"/>
                  &nbsp;&nbsp;&nbsp;Add Comment: <input type="text" name="productComment"/>
                  <input type="submit" value="Submit" action="productRatingComment"/>
              </g:if>
            
              <g:if test="${session.customerId == null}">
                  Please login to rate or comment on this product.
              </g:if>
              

          </g:form>
          
          
          <g:if test="${ratingCommentListSize > 0}">
            <br/>
            <br/>
            <table>
                <g:each in="${ratingComments}" var="instance" status="s">

                  <tr>
                    <td style="color:#555; font-size:smaller">Posted on ${instance.creationDate} by ${instance.customerId}
                    <td>${instance.rating}</td>
                  </tr>
                  <tr>
                    <td colspan="2">${instance.comment}</td>
                  </tr>
                  <tr>
                    <td colspan="2"><hr/></td>
                  </tr>

                </g:each>
            </table>
            <br/>
            <br/>
          </g:if>
          
          <g:if test="${ratingCommentListSize == 0}">
              <br/>
              <br/>
              No comments. Be the first to comment?
              <br/>
              <br/>
          </g:if>

      </div>
  </body>
</html>